var roleManage = function() {
	var _init = function() {
		var table = $('#table_role');
		table
				.dataTable({
					"processing" : true,
					// 开启服务器模式
					serverSide : true,
					"ajax" : {
						 url : "/a/msg/afterSale",
					},
					"autoWidth" : false,
					"columns" : [
							{
								"width" : "20%",
								"render" : function(data, type, row, meta) {
                                    var name="";
                                    if(row.orderProductDetail){
                                        var productName=row.orderProductDetail.productName;
                                        var productSpec=row.orderProductDetail.productSpec;
                                        var productSpec1=row.orderProductDetail.productSpec1;
                                        var productSpec2=row.orderProductDetail.productSpec2;
                                        if(productSpec2){
                                            name= productName+" "+productSpec+productSpec1+productSpec2;
                                        }else  if(productSpec1){
                                            name= productName+" "+productSpec+productSpec1;
                                        }else if(productSpec){
                                            name= productName+" "+productSpec;
                                        }else{
                                            name= productName;
                                        }
                                    }
									if(row.ProSpec==null){
										return row.userName+",申请订单售后</br>"+name;
									}else{
										return row.userName+",申请订单售后</br>"+name;
									}
									
								}
							},
							{
								"width" : "20%",
								"data" : "id"
							},
							{
								"width" : "20%",
								"data" : "createDate"
							},
							{
								"width" : "20%",
								"data" : "status"
							},
							{
								"width" : "20%",
								"data" : "null",
								"defaultContent" : "<button type=\"button\" class=\"btn blue btn_edit_role\">查看</button>"
							} ],
					"language" : {
						"lengthMenu" : "每页显示 _MENU_ 条记录",
						"emptyTable" : "暂无数据记录",
						"info" : "显示 _START_ 至 _END_ 条数据，共 _TOTAL_ 条记录！",
						"zeroRecords" : "没有搜索到匹配记录",
						"infoEmpty" : "",
						"infoFiltered" : "",
						"processing" : ""
					},
					"destroy" : true,
					"pageLength" : 5,
					"order" : [ [ 2, "desc" ] ],
					"columnDefs" : [ {
						"orderable" : false,
						"targets" : [0,1,3,4]
					}
					, {
						"targets" : 1,
						"visible": false
					
					},
					{
						"targets" : 2,
						"render" : function(data, type, row, meta) {
							return moment(data).format('YYYY-MM-DD HH:mm');
						}
					}
					, {
						"targets" : 3,
						"visible": false
					
					}],
					"dom" : "<'row'<'.col-md-6 col-sm-12'><'col-md-6 col-sm-12'>r>"
							+ "<t>" + "<'row'<'col-md-5'i><'col-md-7'>p>",
					"fnInitComplete" : function() {
					}
				});

		table.on('click', '.btn_edit_role', function(event) {
			var oData_arr = table.DataTable().rows($(this).parents("tr"))
			.data(); // 操作行对象
	var _id = oData_arr[0].id;
	var _status = oData_arr[0].status;

	       //根据订单状态查看订单
	                var form = $('#form1').serializeObject();
	                var isRead = form.isread;
						  if(isRead=="1"){//已读
						  switch (_status) {
						  case 0: //退款
								window.location.href="/p/user/refundOrder?id="+ encodeURIComponent(_id);
								break;
							case 1: //拒绝
								window.location.href="/p/user/refundOrder?id="+ encodeURIComponent(_id);
								break;
							case 4://审核
								window.location.href="/p/user/refundOrder?id="+ encodeURIComponent(_id);
								break;
							default://订单详情
								window.location.href="/p/user/refundOrder?id="+ encodeURIComponent(_id);
							break;
							}
					  }else{ //未读,先读再跳转页面,把状态加到后台
						  var sta = _status;
//							window.location.href="/p/msg/custser/reader?id="+ encodeURIComponent(_id)+"&status="+sta;
							window.location.href="/p/user/refundOrder/refundOrder1?id="+ encodeURIComponent(_id)+"&status="+sta;

							 }
         });
	}


	return {
		init : function() {
			_init();
		}

	};

}();

var roleForm = function() {
	// 新建表单验证
	return {
		init : function() {
		}

	};
}();

$(function() {
	roleManage.init();
	roleForm.init();
	// doSearch();
});

function doSearch(){
	 var form = $('#form1').serializeObject();
		var param = {
			"IsRead" : form.isread,
			"orderNo" : form.orderNo
		};
		$('#table_role').DataTable().search(JSON.stringify(param)).draw();
}


function beback() {
	window.location.href = "/p/msg/note";
}

function getCheck() {
	roleManage.init();
}
